#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    bool checkPrime(int n)
    {
        if (n == 1)
            return false;
        for (int i = 2; i <= sqrt(n); i++)
        {
            if ((n % i) == 0)
                return false;
        }
        return true;
    }
    int diagonalPrime(vector<vector<int>>& nums) {
        int n = nums.size(), m = nums[0].size();
        int res = 0;
        int a = 0, b = m - 1;
        for (int i = 0; i < n; i++)
        {
            if (nums[i][a] > res && checkPrime(nums[i][a]))
                res = max(res, nums[i][a]);
            if (nums[i][b] > res && checkPrime(nums[i][b]))
                res = max(res, nums[i][b]);
            ++a; --b;
        }
        return res;
    }
};